<template>
    <div class="window"
         :style="{width:windowWidth+'px'}"
         v-if="show">
      <div class="title">
        <span class="back"
              @click="close">返回</span>
      </div>
      <div class="body">
        <slot></slot>
      </div>
      <template v-if="buttons&&buttons.length>0||showCancel">
        <div class="footer">
          <el-button link
                     @click="close"
                     v-if="showCancel">
            取消
          </el-button>
          <el-button v-for="btn in buttons"
                     :type="btn.type"
                     @click="btn.click">
            {{btn.text}}
          </el-button>
        </div>
      </template>
    </div>
  </template>
  
  <script>
  export default {
    name: 'Window',
    data() {
      return {
        windowWidth: window.innerWidth - 280
      }
    },
    props: {
      show: {
        type: Boolean,
        default: false
      },
      buttons: {
        type: Array
      },
      showCancel: {
        type: Boolean,
        default: true
      }
    },
    methods: {
      close() {
        this.$emit('close')
      }
    }
  }
  </script>
  
  <style lang="scss">
  .window {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: calc(100vh - 70px);
    background: #fff;
    z-index: 50;
    .title {
      height: 30px;
      display: flex;
      align-items: center;
      padding-left: 10px;
      .back {
        font-size: 20px;
        cursor: pointer;
      }
    }
    .body {
      height: calc(100vh - 151px);
      padding: 10px;
      overflow: auto;
    }
    .footer {
      border-top: 1px solid #ddd;
      text-align: center;
      line-height: 50px;
    }
  }
  </style>